//
//  JJAppManager.m
//  DemoPro
//
//  Created by vpjacob on 2017/4/7.
//  Copyright © 2017年 vpjacob. All rights reserved.
//

#import "JJAppManager.h"
#import <YTKNetworkConfig.h>
#import <AFNetworking.h>
#import <MagicalRecord/MagicalRecord.h>
#import "StudentModel.h"

@implementation JJAppManager

+ (instancetype)shareInstance {
    static JJAppManager *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[self alloc] init];
    });
    return instance;
}

- (void)configureThird {
    // 开启网络检测(放在最前面)
    [self configureNetWorkReachability];
    // 配置ping++
    // 配置数据库路径
    [self configureCoreDataPath];
    // 主配置接口配置
//    [self configureRequestFilters];
 
}

#pragma mark - NetWork
- (void)configureRequestFilters {
    
    YTKNetworkConfig *config = [YTKNetworkConfig sharedConfig];
    config.baseUrl = KNB_MAINCONFIGURL;
    
    //https 公匙
//    NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"https" ofType:@"cer"];
//    NSData * certData =[NSData dataWithContentsOfFile:cerPath];
//    NSSet *set = [NSSet setWithObjects:certData, nil];
//    AFSecurityPolicy *securityPolicy = [AFSecurityPolicy defaultPolicy];
//    [securityPolicy setAllowInvalidCertificates:YES];
//    [securityPolicy setValidatesDomainName:NO];
//    [securityPolicy setPinnedCertificates:set];
//    config.securityPolicy = securityPolicy;
    
}



#pragma mark - Configure CoreData

- (void)configureCoreDataPath {
    [MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:@"Model.sqlite"];
    [MagicalRecord setLoggingLevel:MagicalRecordLoggingLevelOff];

    /*
     创建
     */
//        StudentModel *model = [[StudentModel alloc] init];
//    model.name = @"张三1";
//    NSLog(@"%@",model.name);
//    NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
//    NSLog(@"%@",path);
//
//[StudentModel saveWithModel:model resultBlock:^(BOOL success) {
//    NSLog(@"%zd",success);
//}];
    
    /*
     查询
     */
//    NSArray *serach = [StudentModel searchAll];
//    for (StudentModel *model in serach) {
//        NSLog(@"%@",model.name);
//    }

    
}


#pragma mark - NetWorkCheck

- (void)configureNetWorkReachability {
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
}

@end
